3.09 逻辑运算
运算符 | 名称 | 示例 |
---|---|---|
&& | 逻辑与 | x&&y 表示如果x和y都为真,则为真 |
|| | 逻辑或 | x||y表示如果x或y有一个为真,则为真 |
! | 逻辑非 | !x表示如果x不为真,则为真 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript">
var a=4>7 && 5>3 //false
var b=4<7 && 5>3 //true
var c=4>7 || 5>3 //true
document.write("a的值为:",typeof a,",",a,"<br>")
document.write("b的值为:",typeof b,",",b,"<br>")
document.write("c的值为:",typeof c,",",c)
var d=4>7 && 5>3 //false
var d=!(4>7) && 5>3 //true
document.write("d的值为:",typeof d,",",d,"<br>")
</script>
</head>
<body>
</body>
</html>
返回值:
a的值为:boolean,false
b的值为:boolean,true
c的值为:boolean,trued的值为:boolean,true